package com.edu.app.controller.notification;

import com.edu.app.constant.StaticConstant;
import com.edu.app.constant.SysMessage;
import com.edu.app.service.sys.linkservices.SysUserActivityService;
import com.edu.app.util.ErrorUtil;
import com.edu.app.util.JWTUtil;
import com.edu.app.util.MsgUtil;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/notification")
@RestController
public class NotificationController {
    @Autowired
    SysUserActivityService sysUserActivityService;

    @GetMapping(value = "/getPendingActivityNum")
    @RequiresAuthentication
    public ModelMap getPendingActivityNum(@RequestHeader("Authorization") String token, @RequestParam("type") String type, @RequestParam("rolePlay") String rolePlay){

        try{
            String username = JWTUtil.getUsername(token);

            Integer pendingNum = sysUserActivityService.getUserPendingActivityNumber(username, type, rolePlay);
            return MsgUtil.retMsg(SysMessage.GET_PENDING_ACTIVITY_SUCCEED, StaticConstant.PENDING_ACTIVITY, pendingNum);
        }catch(Exception e){
            return ErrorUtil.retErrMsg(e);
        }

    }
}
